/*
 * BanBu_FunctionGuide
 * @description 本文件提供添加引导页的功能
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供添加引导页的功能
 */

#import "BanBu_FunctionGuide.h"
#import "BanBu_FunctionPage.h"
#import "BanBu_FunctionView.h"
#import "AppDataManager.h"
BanBu_FunctionGuide * sigleton = nil;

@implementation BanBu_FunctionGuide
- (void)dealloc
{
    self.targetView = nil;
    [super dealloc];
}
+(BanBu_FunctionGuide *)shareInstance
{
    if(sigleton == nil)
    {
        @synchronized(self)
        {
            sigleton = [[self alloc] init];
            [sigleton initRaysource];
        }
    }
    return sigleton;
}

-(void)initRaysource
{
    pageArray = [[NSMutableArray alloc] initWithCapacity:0];
}
/**
 *	@brief	添加引导页
 *
 *	@param 	_page 	引导页添加的目标View
 *	@param 	_target 	目标引导页的标示 目前两种 FunctionTargetNearby 共两个引导页  FunctionTargetSpace共三个引导页
 */
-(void)addFunctionGuideToPage:(UIView *)_page withKey:(FunctionTarget)_target;
{
    switch (_target) {
        case FunctionTargetNearby:
        {
            if([[UserDefaults valueForKey:@"near"] boolValue])
            {
                return;
            }
            [UserDefaults setValue:[NSNumber numberWithBool:YES] forKeyPath:@"near"];
            
            [pageArray removeAllObjects];
            BanBu_FunctionPage *page1 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleNearTap];
            BanBu_FunctionPage *page2 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleNearFilter];
            [pageArray addObjectsFromArray:@[page1,page2]];

        }
            break;
        case FunctionTargetSpace:
        {
            if([[UserDefaults valueForKey:@"space"] boolValue])
            {
                return;
            }
            [UserDefaults setValue:[NSNumber numberWithBool:YES] forKeyPath:@"space"];

            [pageArray removeAllObjects];
            BanBu_FunctionPage *page1 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleSpaceTap];
            BanBu_FunctionPage *page2 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleSpaceProfile];
            BanBu_FunctionPage *page3 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleSpaceSetting];
            BanBu_FunctionPage *page4 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleSpaceDynamic];
            BanBu_FunctionPage *page5 = [[BanBu_FunctionPage alloc] initWithFunctionPageStyle:FunctionPageStyleSpaceEmoShop];
            [pageArray addObjectsFromArray:@[page1,page2,page3,page4,page5]];
        }
            break;
            
        default:
            break;
    }
    
    self.targetView = _page;
    [self startPlay];
}
/**
 *	@brief	播放引导页
 */
-(void)startPlay
{
    if(pageArray.count)
    {
        BanBu_FunctionPage *page = [pageArray objectAtIndex:0];
        BanBu_FunctionView *guideView = [BanBu_FunctionView instanceTextView];
        guideView.textLabel.frame = page.textFrame;
        guideView.textLabel.text = page.text;
        guideView.imageView.image = [UIImage imageNamed:page.imageName];
        
        guideView.frame = CGRectMake(0, _targetView.frame.size.height-__MainScreen_Height+20, 320, __MainScreen_Height+20);
        
        
        [_targetView addSubview:guideView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [guideView addGestureRecognizer:tap];
    }
}
/**
 *	@brief	引导页的点击事件
 *
 *	@param 	_ges 
 */
-(void)tap:(UITapGestureRecognizer *)_ges

{
    [pageArray removeObjectAtIndex:0];
    [_ges.view removeFromSuperview];
    [self startPlay];
    
}
@end
